package reference;

import java.lang.ref.WeakReference;

/**
 * @author ZhuQi
 * @ClassName WeekReferenceDemo
 * @Date 2022/9/23 11:28
 * @Version 1.0
 * @Description 测试弱引用
 * 弱引用:只要发生GC 就会被回收
 */
public class WeekReferenceDemo {
    public static void main(String[] args) {
        WeakReference weakReference = new WeakReference(1);
        // weakReference:1
        System.out.println("weakReference:" + weakReference.get());

        System.gc();
        // gc after weakReference:null
        System.out.println("gc after weakReference:" + weakReference.get());
    }
}
